﻿@using Microsoft.JSInterop
@using Covenant.Core
@using Covenant.Models.Grunts
@using Covenant.Components.Shared
@inject IJSRuntime IJSRuntime

<CovenantTable TItem="ReferenceAssembly" Items="ReferenceAssemblies.ToList()" SearchRow="IsRowDisplayed"
               IsSearchable="IsSearchable" IsSortable="IsSortable" IsPaginated="IsPaginated" PageLength="PageLength" class="table table-hover">
    <TableHeader>
        <SortableTableHeader TItem="ReferenceAssembly" TItem2="string" GetSortableProperty="(assembly) => assembly.Name">
            <HeaderContent>Name</HeaderContent>
        </SortableTableHeader>
        <SortableTableHeader TItem="ReferenceAssembly" TItem2="Common.DotNetVersion" GetSortableProperty="(assembly) => assembly.DotNetVersion">
            <HeaderContent>DotNetVersion</HeaderContent>
        </SortableTableHeader>
    </TableHeader>
    <TableRow Context="assembly">
        <tr>
            <td>
                <a href="/referenceassembly/edit/@assembly.Id">
                    @assembly.Name
                </a>
            </td>
            <td>@assembly.DotNetVersion</td>
        </tr>
    </TableRow>
</CovenantTable>

@code {
    [Parameter]
    public IEnumerable<ReferenceAssembly> ReferenceAssemblies { get; set; }

    [Parameter]
    public bool IsSearchable { get; set; } = true;

    [Parameter]
    public bool IsSortable { get; set; } = true;

    [Parameter]
    public bool IsPaginated { get; set; } = true;

    [Parameter]
    public int PageLength { get; set; } = 10;

    private bool IsRowDisplayed(ReferenceAssembly assembly, string SearchTerm)
    {
        return SearchTerm == string.Empty ||
            assembly.Name.Contains(SearchTerm, StringComparison.CurrentCultureIgnoreCase) ||
            assembly.DotNetVersion.ToString().Contains(SearchTerm, StringComparison.CurrentCultureIgnoreCase);
    }
}
